const pool = require('../config/db');

const Hashtag = {
    async findByTag(tag, limit = 10, offset = 0) {
        const [rows] = await pool.query(
            'SELECT p.*, ps.likes_count, ps.comments_count, ps.shares_count FROM posts p JOIN post_hashtags ph ON p.post_id = ph.post_id JOIN hashtags h ON ph.hashtag_id = h.hashtag_id LEFT JOIN post_stats ps ON p.post_id = ps.post_id WHERE h.tag = ? AND p.is_active = TRUE ORDER BY p.created_at DESC LIMIT ? OFFSET ?',
            [tag, limit, offset]
        );
        return rows;
    }
};

module.exports = Hashtag;